package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.RoleDao;
import com.ef.domain.Role;
import com.ef.service.RoleService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class RoleServiceImpl extends BaseServiceImpl implements RoleService {

	private RoleDao roleDao;

	public void delete(Role entity) {
		entity.setStatus(StatusType.INVALID);
		roleDao.update(entity);
	}

	public PaginationSupport<Role> findByExample(CustomExample<Role> example,
			int startIndex, int pageSize) {
		return roleDao.findPageByExample(example, startIndex, pageSize);
	}

	public Role findById(Long id) {
		return roleDao.findById(id);
	}

	public void saveOrUpdate(Role entity) {
		roleDao.saveOrUpdate(entity);
	}
	
	public List<Role> findAll(){
		DetachedCriteria criteria = DetachedCriteria.forClass(Role.class);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return roleDao.findAllByCriteria(criteria);
	}

	public RoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

}
